<template>
  <div id="chat">
    <div class="chat-head">
      <div class="chat-head-left">
        <div class="chat-head-img">
          <img alt="" src="../../assets/img/headportrait.png">
        </div>
        <div class="chat-head-name">
          {{name}}
        </div>
      </div>
      <div class="chat-head-right">
        <i @click="close" class="el-icon-close"></i>
      </div>
    </div>
    <div class="chat-content">
      <ul class="chat-content-content">

        <li :key="idx" v-for="(item,idx) in chat">
          <div :class="item.name==name?'active':''" class="chat-content-img">
            <img alt="" src="../../assets/img/headportrait.png">
          </div>
          <div :class="item.name==name?'active':''" class="chat-content-chat">
            <!--            <div :class="item.name==name?'activeText':''" class="chat-content-time">{{item.name}}&#45;&#45;{{item.time}}</div>-->
            <div :class="item.name==name?'activeColor':''" class="chat-content-123">{{item.content}}</div>
          </div>
        </li>
      </ul>
    </div>
    <div class="chat-foot">
      <div class="chat-foot-content">
        <div class="chat-foot-input">
          <textarea placeholder="" v-model="textarea"></textarea>
        </div>
        <div class="chat-foot-btn">
          <i @click="send" class="el-icon-position"></i>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
    export default {
        name: "Chat.vue",
        data() {
            return {
                name: "",
                textarea: "",
                chat: [
                    {name: "boss", time: "2019/12/22 12-02-12", content: this.$t('other.hello')},
                ]
            }
        },
        methods: {
            close() {
                this.$emit('closeChat');
            },
            send() {
                if (this.textarea != '') {
                    let time = this.getDate();
                    this.chat.push({name: this.name, time: time, content: this.textarea});
                    this.textarea = '';
                }
            },
            getDate() {
                let date = new Date();
                let year = date.getFullYear();
                let month = date.getMonth() + 1;
                let day = date.getDate();
                let hours = date.getHours();
                let minu = date.getMinutes();
                let sec = date.getSeconds();
                return `${year}/${month}/${day} ${hours}-${minu}-${sec}`
            }
        },
        mounted() {
            this.name = this.$Cookies.get('user');
        }
    }
</script>

<style scoped>
  #chat {
    width: 535px;
    height: 660px;
    overflow: hidden;
    border-radius: 10px;
    background-color: rgb(245, 246, 248);
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    margin: auto;
  }

  .chat-head {
    width: 100%;
    height: 60px;
    background-color: rgb(144, 147, 153);
    padding: 0 10px;
  }

  .chat-head-left {
    float: left;
    width: auto;
    height: 100%;
    display: flex;
    justify-content: left;
    align-items: center;
  }

  .chat-head-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }

  .chat-head-img img {
    display: block;
    width: 100%;
    height: 100%;
  }

  .chat-head-name {
    margin-left: 10px;
    line-height: 60px;
  }

  .chat-head-right {
    float: right;
    width: auto;
    height: 60px;
    line-height: 60px;
  }

  .chat-content {
    width: 100%;
    height: 520px;
    padding: 10px 20px;
    overflow-y: scroll;
    overflow-x: hidden;
  }

  .chat-content-content {
    width: 100%;
    height: 100%;
    list-style: none;
  }

  .chat-content-content li {
    width: 100%;
    height: auto;
  }

  .chat-content-content li:after {
    content: ' ';
    display: block;
    height: 0;
    clear: both;
  }

  .chat-content-img {
    float: left;
    width: 40px;
    height: 40px;
  }

  .chat-content-img img {
    display: block;
    width: 100%;
    height: 100%;
  }

  .chat-content-chat {
    float: left;
    width: auto;
    max-width: calc(100% - 40px);
    min-height: 60px;
    height: auto;
    padding: 0 10px;
  }

  .active {
    float: right;
  }

  .activeColor {
    background-color: rgb(144, 147, 153) !important;
    color: #fff;
  }

  .activeText {
    text-align: right;
  }

  .chat-content-time {
    width: auto;
    font-size: 12px;
    padding: 0 10px;
  }

  .chat-content-123 {
    width: auto;
    max-width: 100%;
    min-height: 40px;
    padding: 0 20px;
    border-radius: 30px;
    background-color: #fff;
    font-size: 16px;
    line-height: 34px;
    text-justify: newspaper;
    word-break: break-all;
  }

  .chat-foot {
    width: 100%;
    height: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .chat-foot-content {
    width: 500px;
    height: 50px;
    background-color: #fff;
    border-radius: 10px;
    padding: 0 10px;
    overflow: hidden;
  }

  .chat-foot-input {
    float: left;
    width: 430px;
    height: 100%;
  }

  .chat-foot-input textarea {
    outline: none;
    width: 100%;
    height: 100%;
    resize: none;
    border: 0;
    padding: 4px 8px;
    font-size: 14px;
    line-height: 30px;
    -ms-overflow-style: none;
    overflow: -moz-scrollbars-none;
  }

  .chat-foot-input textarea::-webkit-scrollbar {
    width: 0 !important
  }

  .chat-foot-input textarea:focus {
    border: none;
  }

  .chat-foot-btn {
    float: right;
    width: 50px;
    height: 50px;
    line-height: 50px;
  }

  .chat-foot-btn i {
    display: inline-block;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: rgb(144, 147, 153);
    text-align: center;
    line-height: 40px;
    color: #fff;
  }
</style>
